package com.ruoyi.controller;

import com.sxftech.resp.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.entity.BizPriceParkingSpace;
import com.ruoyi.service.BizPriceParkingSpaceService;
import com.ruoyi.bean.BizPriceParkingSpaceFrom;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 价格体系与车位关系表 前端控制器
 * </p>
 *
 * @author liuxing
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/bizPriceParkingSpace")
@Slf4j
public class BizPriceParkingSpaceController {

	@Autowired
	private BizPriceParkingSpaceService bizPriceParkingSpaceService;

	@ApiOperation(value="新增")
	@PutMapping
	public Object create(@RequestBody BizPriceParkingSpaceFrom bizPriceParkingSpace) {

		try {
			bizPriceParkingSpaceService.create(bizPriceParkingSpace);
			return ResponseData.success("新增成功");
		} catch (Exception e) {
			log.error("新增价格体系与车位关系表失败 e:{}", e);
			return ResponseData.fail();
		}

	}

	@ApiOperation(value="修改")
	@PostMapping
	public Object modify(@RequestBody BizPriceParkingSpaceFrom bizPriceParkingSpace) {

		try {
			Object result = bizPriceParkingSpaceService.modify(bizPriceParkingSpace);
			return result;
		} catch (Exception e) {
			log.error("修改价格体系与车位关系表失败 e:{}", e);
			return ResponseData.fail();
		}

	}

	@ApiOperation(value="详情")
	@GetMapping(value = "/{id}")
	public Object detail(@PathVariable("id") String id) {

		try {
			BizPriceParkingSpaceFrom bizPriceParkingSpace = bizPriceParkingSpaceService.findById(id);
			if (bizPriceParkingSpace == null) {
				return ResponseData.notFound();
			}
			return ResponseData.success(bizPriceParkingSpace);
		} catch (Exception e) {
			log.error("查询价格体系与车位关系表详情失败 e:{}", e);
			return ResponseData.fail();
		}

	}

	@ApiOperation(value="删除")
	@DeleteMapping(value = "/{id}")
	public Object remove(@PathVariable("id") String id) {

		try {
			Object result =bizPriceParkingSpaceService.remove(id); 
			return result;
		} catch (Exception e) {
			log.error("删除价格体系与车位关系表失败 e:{}", e);
			return ResponseData.fail();
		}
	}

	@ApiOperation(value="列表查询")
	@GetMapping(value = "/list")
	public Object selectList(@RequestParam(defaultValue = "1") Integer page,
			@RequestParam(defaultValue = "10") Integer size, BizPriceParkingSpaceFrom ibean) {

		try {
			IPage data = bizPriceParkingSpaceService.pageList(page, size, ibean);

			return ResponseData.success(data);
		} catch (Exception e) {
			log.error("查询价格体系与车位关系表列表异常 e:{}", e);
			return ResponseData.fail();
		}
	}
	
}
